package cn.edu.zjgsu.ito.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.edu.zjgsu.ito.service.UserCourierManageServiceI;
import cn.edu.zjgsu.ito.util.Constant;
import cn.edu.zjgsu.ito.vo.CourierOrderMessageShowVo;
import cn.edu.zjgsu.ito.vo.CourierStateSaveVo;
import cn.edu.zjgsu.ito.vo.CourierStateShowVo;
import cn.edu.zjgsu.ito.vo.OrderIdVo;
import cn.edu.zjgsu.ito.vo.OrderNoCourierShowVo;
import cn.edu.zjgsu.ito.vo.UserCourierStateVo;
import cn.edu.zjgsu.ito.vo.UserPayCourierDepositVo;
import cn.edu.zjgsu.ito.vo.UserSubmitCourierSaveVo;

/**
 * 用户快递员控制类
 * @author Administrator
 */
@Controller
@RequestMapping("userCourierManageController")
public class UserCourierManageController {

	@Autowired
	private UserCourierManageServiceI userCourierManageService;
	
	/**
	 * 用户申请成为快递员接口<br/>
	 * 返回用户快递员状态
	 * @param userIdVo
	 * @return
	 */
	@RequestMapping(value="wantToBeCourier",method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> wantToBeCourier(HttpSession session){
		
		int userId = Integer.valueOf(session.getAttribute("userId").toString());
		
		Map<String,Object> result = new HashMap<String,Object>();
		
		UserCourierStateVo userCourierStateVo = userCourierManageService.wantToBeCourier(userId);
		
		result.put("msg", userCourierStateVo);
		result.put("code", Constant.OK);
		
		return result;
	}
	
	/**
	 * 用户请求审核快递员接口<br/>
	 * @param userSubmitCourierSaveVo
	 * @return
	 */
	@RequestMapping(value="requestAuditCourier",method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> requestAuditCourier(UserSubmitCourierSaveVo userSubmitCourierSaveVo,HttpSession session){
		
		int userId = Integer.valueOf(session.getAttribute("userId").toString());
		
		Map<String,Object> result = new HashMap<String, Object>();
		
		UserCourierStateVo userCourierStateVo = userCourierManageService.requestAuditCourier(userSubmitCourierSaveVo,userId);
		
		result.put("msg",userCourierStateVo);
		result.put("code", Constant.OK);
		
		return result;
	}
	
	/**
	 * 用户审核通过之后缴纳快递员押金接口<br/>
	 * @param userIdVo
	 * @return
	 */
	@RequestMapping(value="payTheDeposit",method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object>  payTheDeposit(UserPayCourierDepositVo userPayCourierDepositVo,HttpSession session){
		
		int userId = Integer.valueOf(session.getAttribute("userId").toString());
		
		Map<String,Object> result = new HashMap<String ,Object>();
		
		UserCourierStateVo userCourierStateVo =userCourierManageService.payTheDeposit(userPayCourierDepositVo,userId);
		
		result.put("msg",userCourierStateVo);
		result.put("code", Constant.OK);
		
		return result;
	}
	
	/**
	 * 快递员接单首页接口<br/>
	 * @param userIdVo
	 * @return
	 */
	@RequestMapping(value="courierHome",method=RequestMethod.POST)
	@ResponseBody
	public Map<String ,Object> courierHome(){
		
		Map<String,Object> result = new HashMap<String ,Object>();
		
		List<OrderNoCourierShowVo> orderNoCourierShowVos = userCourierManageService.courierHome();
		
		result.put("msg", orderNoCourierShowVos);
		result.put("code", Constant.OK);
		
		return result;
	}
	
	/**
	 * 快递员接单首页筛选接口<br/>
	 * @param userIdVo
	 * @return
	 */
	@RequestMapping(value="courierChooseHome",method=RequestMethod.POST)
	@ResponseBody
	public Map<String ,Object> courierChooseHome(int temp){
		
		Map<String,Object> result = new HashMap<String ,Object>();
		
		List<OrderNoCourierShowVo> orderNoCourierShowVos = userCourierManageService.courierChooseHome(temp);
		
		result.put("msg", orderNoCourierShowVos);
		result.put("code", Constant.OK);
		
		return result;
	}
	
	/**
	 * 快递员接单首页搜索接口<br/>
	 * @param userIdVo
	 * @return
	 */
	@RequestMapping(value="courierSelectHome",method=RequestMethod.POST)
	@ResponseBody
	public Map<String ,Object> courierSelectHome(String temp){
		
		Map<String,Object> result = new HashMap<String ,Object>();
		
		List<OrderNoCourierShowVo> orderNoCourierShowVos = userCourierManageService.courierSelectHome(temp);
		
		result.put("msg", orderNoCourierShowVos);
		result.put("code", Constant.OK);
		
		return result;
	}
	
	/**
	 * 快递员接单按钮接口
	 * @param orderIdVo
	 * @param session
	 * @return
	 */
	@RequestMapping(value="acceptOrder",method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> acceptOrder(OrderIdVo orderIdVo,HttpSession session){
		
		int userId = Integer.valueOf(session.getAttribute("userId").toString());
		
		Map<String,Object> result = new HashMap<String ,Object>();
		
		int temp = userCourierManageService.acceptOrder(orderIdVo,userId);
		
		if(temp == 1){
			result.put("code", Constant.OK);
		}else{
			result.put("code", Constant.FAIL);
		}
		
		return result;
	}
	
	/**
	 * 快递员查看自己订单
	 * @param session
	 * @return
	 */
	@RequestMapping(value="courierOwnOrder",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> courierOwnOrder(HttpSession session){
		int userId = Integer.valueOf(session.getAttribute("userId").toString());
		Map<String,Object> result = new HashMap<String ,Object>();
		List<CourierOrderMessageShowVo> courierOrderMessageShowVos = userCourierManageService.courierOwnOrder(userId);
		
		result.put("msg", courierOrderMessageShowVos);
		result.put("code", Constant.OK);
		return result;
	}
	
	/**
	 * 快递员查看自己订单
	 * @param session
	 * @return
	 */
	@RequestMapping(value="courierSelectOwnOrder",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> courierSelectOwnOrder(String temp,HttpSession session){
		int userId = Integer.valueOf(session.getAttribute("userId").toString());
		Map<String,Object> result = new HashMap<String ,Object>();
		List<CourierOrderMessageShowVo> courierOrderMessageShowVos = userCourierManageService.courierSelectOwnOrder(temp,userId);
		
		result.put("msg", courierOrderMessageShowVos);
		result.put("code", Constant.OK);
		return result;
	}
	
	/**
	 * 快递员查看订单详情
	 * @param orderIdVo
	 * @param session
	 * @return
	 */
	@RequestMapping(value="courierOrderMessage",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> courierOrderMessage(OrderIdVo orderIdVo,HttpSession session){
		
		Map<String,Object> result = new HashMap<String ,Object>();
		
		CourierOrderMessageShowVo courierOrderMessageShowVo = userCourierManageService.courierOrderMessage(orderIdVo);
		
		result.put("msg", courierOrderMessageShowVo);
		result.put("code",Constant.OK);
		return result;
		
	}
	
	/**
	 * 快递员更改状态接口
	 * @param orderIdVo
	 * @return
	 */
	@RequestMapping(value="courierChangeState",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> courierChangeState(CourierStateSaveVo courierStateSaveVo){
		
		Map<String,Object> result = new HashMap<String ,Object>();
		
		CourierStateShowVo courierStateShowVo = userCourierManageService.courierChangeState(courierStateSaveVo);
		
		result.put("msg", courierStateShowVo);
		result.put("code", Constant.OK);
		return result;
	}
	
	
}
